<?php
namespace App\Query;

use App\Model\Config;

class ConfigQuery extends \HyperfStore\Query
{
    // 构建模型
    protected static function build()
    {
        return new Config;
    }
    
    // 所有配置
    public static function all()
    {
        return static::model()->get();
    }
    
    // 整理配置
    public static function get()
    {
        $data = [];
        
        foreach(static::all() as $config)
        {
            $data[$config->name] = $config->value;
        }
        
        return $data;
    }
    
    // 配置比例
    public static function bi($data, $name, $money)
    {
        return bcmul($money, (float) $data[$name] / 100, 2);
    }
}